#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>

typedef struct 
{
	int id ; 
	char name[20] ;
	double sal;
}Employee;

int main()
{
	int fd = open("emp.dat" , O_RDWR , 0666);
	if(fd == -1) perror("open") , exit(-1);
	
	void * p = mmap( 0 , sizeof(Employee)*3 , PROT_WRITE | PROT_READ , MAP_SHARED , fd , 0 );
	if(p == MAP_FAILED) perror("mmap") , exit(-1);
	
	Employee *emp = p ;	
	for(int i = 0 ; i < 3 ; ++i)
	{
		printf("the consumer id : %d , consumer's name : %s , sal : %lf\n", emp[i].id , emp[i].name , emp[i].sal);
	}	
	munmap(p , sizeof(Employee)*3);
}
